/*
@hehung
2023-5-22
email: 1398660197@qq.com
wechat: hehung95
reproduced and please indicate the source @hehung
*/

#include "app_common.h"

/* sci6 i2c for OLED and HS303 */
i2c_master_event_t sci6_i2c_event = I2C_MASTER_EVENT_ABORTED;
/* sci3 i2c for MAX30102 */
i2c_master_event_t sci3_i2c_event = I2C_MASTER_EVENT_ABORTED;

/* Initialize for I2c driver */
void I2c_Init(void)
{
	fsp_err_t err;
	
	// Initialize the sci6 i2c
	// scl - P505
	// sda - P506
	err = R_SCI_I2C_Open(&g_sci6_i2c_ctrl, &g_sci6_i2c_cfg);
	assert(FSP_SUCCESS == err);
	
	// Initialize the sci3 i2c
	// scl - P408
	// sda - P409
	err = R_SCI_I2C_Open(&g_sci3_i2c_ctrl, &g_sci3_i2c_cfg);
	assert(FSP_SUCCESS == err);
}

/* SCI6 I2C interrupt callback */
void sci6_i2c_master_callback(i2c_master_callback_args_t *p_args)
{
    sci6_i2c_event = I2C_MASTER_EVENT_ABORTED;
	
    if (NULL != p_args)
    {
        /* capture callback event for validating the i2c transfer event*/
        sci6_i2c_event = p_args->event;
    }
}

/* SCI3 I2C interrupt callback */
 void sci3_i2c_master_callback(i2c_master_callback_args_t *p_args)
 {
     sci3_i2c_event = I2C_MASTER_EVENT_ABORTED;
	
     if (NULL != p_args)
     {
         /* capture callback event for validating the i2c transfer event*/
         sci3_i2c_event = p_args->event;
     }
 }
